package com.itany.corejava.code06_面向对象.bms;

/**
 * @author 石小俊
 * @date 2024年02月26日 9:51
 */
public class LoanCreditAccount extends CreditAccount implements Loanable{
    private double loanAmount;//贷款金额

    public double getLoanAmount() {
        return loanAmount;
    }

    public void setLoanAmount(double loanAmount) {
        this.loanAmount = loanAmount;
    }

    /**
     * 贷款方法
     * @param money 贷款金额
     */
    @Override
    public void providerLoan(double money) {
        loanAmount+=money;
    }

    /**
     * 还款方法
     * @param money 还款金额
     * @return 还款是否成功
     */
    @Override
    public boolean payLoan(double money) {
        //对于贷款的信用账户
        //账户余额+可透支额度>=还款金额，才可以成功还款
        if(getBalance()+getLimit()>=money){//1000   2000   2500

            //还贷后当前账户余额会减少
            setBalance(getBalance()-money);

            //剩余贷款金额会减少
            loanAmount-=money;
            return true;
        }
        return false;
    }

    /**
     * 查询剩余贷款金额
     * @return 返回剩余的贷款金额
     */
    @Override
    public double queryLoan() {
        return this.loanAmount;
    }
}
